package com.decent.ejfadmin.finance.controller;

import com.decent.ejfadmin.common.bean.MessageBean;
import com.decent.ejfadmin.common.bean.OtherpayConfig;
import com.decent.ejfadmin.finance.service.OtherpayConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

/**
 * @author weicx
 * @date 2019/02/24
 */
@RestController
@RequestMapping("OtherpayConfigController")
@Slf4j
public class OtherpayConfigController {

    @Autowired
    private OtherpayConfigService otherpayConfigService;

    /**
     * 查询代付配置
     *
     * @return
     */
    @RequestMapping("queryOtherpayConfig")
    public List<OtherpayConfig> queryOtherpayConfig() {
        try {
            return otherpayConfigService.queryOtherpayConfig();
        } catch (Exception e) {
            log.warn("查询代付配置异常[{}]", e.getMessage(), e);
            return Collections.emptyList();
        }
    }

    /**
     * 修改限额
     *
     * @param otherpayConfig 代付配置
     * @return
     */
    @RequestMapping("updateOtherpayConfig")
    public MessageBean updateOtherpayConfig(OtherpayConfig otherpayConfig) {
        try {
            return otherpayConfigService.updateOtherpayConfig(otherpayConfig);
        } catch (Exception e) {
            log.warn("修改限额[{}]异常[{}]", otherpayConfig, e.getMessage(), e);
            return MessageBean.fail();
        }

    }

    /**
     * 新增代付配置
     *
     * @param otherpayConfig 代付配置
     * @return
     */
    @RequestMapping("insertOtherpayConfig")
    public MessageBean insertOtherpayConfig(OtherpayConfig otherpayConfig) {
        try {
            return otherpayConfigService.insertOtherpayConfig(otherpayConfig);
        } catch (Exception e) {
            log.warn("新增代付配置[{}]异常[{}]", otherpayConfig, e.getMessage(), e);
            return MessageBean.fail();
        }
    }

    /**
     * 修改代付状态
     *
     * @param otherpayConfig 代付配置
     * @return
     */
    @RequestMapping("updateOtherpayState")
    public MessageBean updateOtherpayState(OtherpayConfig otherpayConfig) {
        try {
            return otherpayConfigService.updateOtherpayState(otherpayConfig);
        } catch (Exception e) {
            log.warn("修改代付状态[{}]异常[{}]", otherpayConfig, e.getMessage(), e);
            return MessageBean.fail();
        }
    }

    /**
     * 代付提现开关 true 开启 false 关闭
     *
     * @return
     */
    @RequestMapping(value = "getOtherpayStatus")
    public boolean getOtherpayStatus() {
        try {
            return otherpayConfigService.getOtherpayStatus();
        } catch (Exception e) {
            log.warn("查询代付提现开关异常[{}]", e.getMessage(), e);
            return true;
        }

    }

    /**
     * 代付提现开关 true 开启 false 关闭
     *
     * @param status
     * @return
     */
    @RequestMapping(value = "changeOtherpayStatus")
    public MessageBean changeOtherpayStatus(Integer status) {
        try {
            return otherpayConfigService.changeOtherpayStatus(status);
        } catch (Exception e) {
            log.warn("查询代付提现开关异常[{}]", e.getMessage(), e);
            return MessageBean.fail();
        }
    }
}
